package com.cskaoyan.app.controller;

import com.cskaoyan.app.bean.common.BaseRespVo;
import com.cskaoyan.app.bean.common.CommonData;
import com.cskaoyan.app.bean.po.MarketBrand;
import com.cskaoyan.app.bean.po.MarketCategory;
import com.cskaoyan.app.bean.vo.CategoryDataVo;
import com.cskaoyan.app.bean.vo.CategoryL1;
import com.cskaoyan.app.service.AdminCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 廖平安
 * @CreateTime: 2022-12-29  16:32
 * @Description: TODO
 * @Version: 1.0
 */
@RequestMapping("admin/category")
@RestController
public class AdminCategoryController {
    @Autowired
    AdminCategoryService categoryService;

    @GetMapping("list")
    public BaseRespVo<CommonData<CategoryDataVo>> list() {
        CommonData<CategoryDataVo> data = categoryService.list();
        return BaseRespVo.ok(data);
    }

    @GetMapping("l1")
    public BaseRespVo<CommonData<CategoryL1>> l1() {
        CommonData<CategoryL1> data = categoryService.l1();
        return BaseRespVo.ok(data);
    }

    @PostMapping("create")
    public BaseRespVo<MarketCategory> create(@RequestBody MarketCategory marketCategory) {
        MarketCategory data = categoryService.create(marketCategory);
        return BaseRespVo.ok(data);
    }
    @PostMapping("update")
    public BaseRespVo update(@RequestBody MarketCategory category) {
        categoryService.update(category);
        return BaseRespVo.ok();
    }
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody CategoryDataVo categoryDataVo){
        categoryService.delete(categoryDataVo);
        return BaseRespVo.ok();
    }
}
